package com.gomore.opple.module.gooddetail;

import android.os.Bundle;

import com.bumptech.glide.Glide;
import com.gomore.opple.R;
import com.gomore.opple.module.BaseActivity;
import com.gomore.opple.module.IntentStart;

import javax.inject.Inject;

/**
 * Created by asus on 2017/5/9.
 */
public class GoodDetailActivity extends BaseActivity {
    @Inject
    GoodDetailPresenter goodDetailPresenter;

    private GoodDetailFragment goodDetailFragment;
    private String goodId;

    @Override
    protected void initalizeViewData() {
        super.initalizeViewData();
        if (getIntent() != null && getIntent().getStringExtra(IntentStart.GOODID) != null) {
            goodId = getIntent().getStringExtra(IntentStart.GOODID);
        }
    }

    @Override
    protected void initalizeViews() {
        if (goodDetailFragment == null) {
            goodDetailFragment = GoodDetailFragment.getInstance(this);
            Bundle bundle = new Bundle();
            bundle.putString(IntentStart.GOODID, goodId);
            goodDetailFragment.setArguments(bundle);
            replaceFragment(goodDetailFragment, false, "add_good_detail_view");
        }
    }

    @Override
    protected void initializeDependencyInjector() {
        DaggerGoodDetailComponent.builder()
                .dataRepositoryComponent(getRepositoryComponent())
                .goodDetailPresenterModule((new GoodDetailPresenterModule(goodDetailFragment)))
                .build()
                .inject(this);
    }

    @Override
    protected int getLayoutView() {
        return R.layout.activity_good_detail;
    }

    @Override
    public void onRightIconClick() {
        super.onRightIconClick();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Glide.get(GoodDetailActivity.this).clearMemory();//清理内存缓存  可以在UI主线程中进行
        System.gc();
    }
}
